<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>工艺进度看板</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">项目编号</label>
                                    <input id="query-proCode" type="text" name="code" class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="name" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-demander">需方</label>
                                    <input id="query-demander" type="text" name="demander" class="form-control"
                                           placeholder="请输入需方">
                                </div>
                                <div class="form-group">
                                    <label for="query-address">安装地点</label>
                                    <input id="query-address" type="text" name="address" class="form-control"
                                           placeholder="请输入地点">
                                </div>
                                <!--<div class="form-group">-->
                                <!--<label for="query-proNum">项目数量</label>-->
                                <!--<input id="query-proNum" type="text" name="num" class="form-control"-->
                                <!--placeholder="请输入数量">-->
                                <!--</div>-->
                                <!--<div class="form-group">-->
                                <!--<label for="query-special">专业</label>-->
                                <!--<select id="query-special" class="form-control" name="special">-->
                                <!--<option value="" selected="selected">请选择</option>-->
                                <!--<option value="机械" >机械</option>-->
                                <!--<option value="流体">流体</option>-->
                                <!--</select>-->
                                <!--</div>-->
                                <!--<div class="form-group">-->
                                <!--<label for="query-part">部分</label>-->
                                <!--<input id="query-part" type="text" name="part" class="form-control"-->
                                <!--placeholder="请输入部分">-->
                                <!--</div>-->
                                <div class="form-group">
                                    <label for="query-craftStatus">工艺编制状态</label>
                                    <select id="query-craftStatus" class="form-control" name="craftStatus">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="1">未开始</option>
                                        <option value="2">执行中</option>
                                        <option value="3">已完成</option>
                                        <option value="4">不需要</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-materialStatus">原材料计划状态</label>
                                    <select id="query-materialStatus" class="form-control" name="materialStatus">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="1">未开始</option>
                                        <option value="2">执行中</option>
                                        <option value="3">已完成</option>
                                        <option value="4">不需要</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-outsourcingStatus">外协件计划状态</label>
                                    <select id="query-outsourcingStatus" class="form-control" name="outsourcingStatus">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="1">未开始</option>
                                        <option value="2">执行中</option>
                                        <option value="3">已完成</option>
                                        <option value="4">不需要</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-costStatus">成本信息输出状态</label>
                                    <select id="query-costStatus" class="form-control" name="costStatus">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="1">未开始</option>
                                        <option value="3">已完成</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-projectClassify">设计类型</label>
                                    <select id="query-projectClassify" class="form-control" name="projectClassify">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="1">设计</option>
                                        <option value="2">非设计</option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" style="width: 99.9%;"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table;
    var statusName = ["", "未开始", "执行中", "已完成", "不需要"];
    var statusColor = ["", "", "#f39c12", "#00a65a", "#00acd6"];
    var classType = ["", " label-default", " label-warning", " label-success", " label-primary"];

    function yearSelectCreate() {
        var myDate = new Date();
        var endYear = myDate.getFullYear();
        for (var i = endYear; i >= 2016; i--) {
            if (i === 2016)
                $("#query-year").append("<option value='" + i + "'>" + i + "年及以前" + "</option>");
            else
                $("#query-year").append("<option value='" + i + "'>" + i + "年" + "</option>");
        }
    }

    /**
     * 合并单元格
     * @param data  原始数据（在服务端完成排序）
     * @param fieldName 合并属性名称
     * @param fiedArry 待合并列
     * @param colspan   合并列
     * @param target    目标表格对象
     */
    function mergeCells(data, fieldName, fiedArry, colspan, target) {
        var valueArry = new Array();//数组只记录值
        for (var i = 0; i < data.length; i++) {
            for (var prop in data[i]) {
                if (prop == fieldName) {
                    var key = data[i][prop]
                    valueArry[i] = key;
                    break;
                }
            }
        }

        var numArry = new Array();//记录值出现的次数  一会就通过循环次数组  合并单元格
        var value = valueArry[0];//初始值
        var num = 0;//记录值出现的次数
        var index1 = 0;//numArry的下标
        for (var i = 0; i <= valueArry.length; i++) {
            if (i == valueArry.length) {//解决最后一次赋值
                numArry[index1] = num;
                break;
            }
            if (value == valueArry[i]) {
                num++;//list下一个值与变量value值相同时，num+1，下标不变
            } else {
                value = valueArry[i];//如果值不相等就把下一个值   赋值给value变量
                numArry[index1] = num;//把value变量之前的值 出现的次数记录下来
                num = 1;// 新的value值出现一次
                index1++;//下标+1;
            }
        }

        var index = 0;
        for (var i = 0; i < numArry.length; i++) {
            var count = numArry[i] * 1;
            $(target).bootstrapTable('mergeCells', {
                index: index,
                field: fiedArry,
                colspan: colspan,
                rowspan: count
            });
            index += count;
        }
    }

    $(function () {
        yearSelectCreate();
        /** 设计进度列表 */
        table = js.table.init({
            url: ctx + "craft/proQuery/listPart",
            onLoadSuccess: function (data) {
                var dataSource = $('#bootstrap-table').bootstrapTable('getData', true);
                mergeCells(dataSource, "code", "code", 1, $('#bootstrap-table')); //合并单元格
                mergeCells(dataSource, "code", "name", 1, $('#bootstrap-table')); //合并单元格
                mergeCells(dataSource, "code", "demander", 1, $('#bootstrap-table')); //合并单元格
                mergeCells(dataSource, "code", "address", 1, $('#bootstrap-table')); //合并单元格
                mergeCells(dataSource, "code", "num", 1, $('#bootstrap-table')); //合并单元格
                mergeCells(dataSource, "code", "operate", 1, $('#bootstrap-table')); //合并单元格
                mergeCells(dataSource, "code", "projectClassify", 1, $('#bootstrap-table')); //合并单元格
            },
            columns: [
                {

                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                // {title: "行号", field: 'proId'},
                {title: "项目编号", field: 'code'},
                {title: "项目名称", field: 'name',width:'160'},
                {title: "需方", field: 'demander',width:'150'},
                {title: "安装地点", field: 'address',width:'150'},
                {title: "数量", field: 'num'},
                {title: "设计类型", field: 'projectClassify',
                    formatter: function (value) {
                        if (value == 1) {
                            return "设计"
                        }
                        if (value == 2) {
                            return "非设计"
                        }
                        return value;
                    }},
                // {title: "部分", field: 'part'},
                {
                    title: "工艺科室", field: 'deptName',
                    formatter: function (value) {
                        if (value == null) {
                            return "工艺一科"
                        }
                        return value;
                    }
                },
                {
                    title: "工艺编制", field: 'craftStatus',
                    formatter: function (value) {
                        return '<span class="badge' + classType[value] + '">' + statusName[value] + '</span>';
                        // return statusName[value];
                    }
                },
                {
                    title: "原材料计划", field: 'materialStatus',
                    formatter: function (value) {
                        return '<span class="badge' + classType[value] + '">' + statusName[value] + '</span>';
                        // return statusName[value];
                    }
                },
                {
                    title: "外协件计划", field: 'outsourcingStatus',
                    formatter: function (value) {
                        return '<span class="badge' + classType[value] + '">' + statusName[value] + '</span>';
                        // return statusName[value];
                    }
                },
                {
                    title: "成本信息输出", field: 'costStatus',
                    formatter: function (value) {
                        return '<span class="badge' + classType[value] + '">' + statusName[value] + '</span>';
                        // return statusName[value];
                    }

                },
                // {title: "备注", field: 'comment'},
                {
                    title: "操作", field: 'operate',
                    formatter: function (value, row) {
                        let actions = [];
                        actions.push('<a target="_blank"  class="btn btn-info btn-xs" href="' + ctx + 'craft/proQuery/infoPart/' + row.proId + '"> 查看</a> ');
                        return actions.join('');
                    }
                }
            ]
        });
    });
</script>
</body>
</html>
